package com.jackstraw.jack_base.datasource.jpa.service.impl;

import com.jackstraw.jack_base.datasource.common.aspect.annotation.DataSourceNameCut;
import com.jackstraw.jack_base.datasource.common.entity.enums.DataSourceTypeEnum;
import com.jackstraw.jack_base.datasource.jpa.base.dao.BaseDao;
import com.jackstraw.jack_base.datasource.jpa.base.service.impl.JpaServiceImpl;
import com.jackstraw.jack_base.datasource.jpa.dao.database.UserDao;
import com.jackstraw.jack_base.datasource.jpa.entity.bo.UserBo;
import com.jackstraw.jack_base.datasource.jpa.entity.po.UserPo;
import com.jackstraw.jack_base.datasource.jpa.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@DataSourceNameCut(dataSourceTypeEnum = DataSourceTypeEnum.database, dataSourceName = "dataBaseName2")
public class UserServiceImpl2 extends JpaServiceImpl<UserDao, UserPo, UserBo, String> implements UserService {

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void aaa() {
        BaseDao baseDao = this.getBaseDao();

        UserDao dao = this.getDao();

        UserPo userPo = new UserPo();
        userPo.setEmail("999");
        userPo.setLastName("baseDao.insert");

        baseDao.insert(userPo);
        UserPo userPo2 = new UserPo();
        userPo2.setEmail("999");
        userPo2.setLastName("dao1.save");
        dao.saveAndFlush(userPo2);

        List<UserPo> all = dao.findAll();

        List<UserPo> userPos = baseDao.queryAll(this.getPoClass());

        log.info("{}", userPos);


    }
}
